package cn.italkcloud.cph.service.impl;

import cn.italkcloud.cph.constants.enums.vos.FeeLogTypeEnum;
import cn.italkcloud.cph.entity.VosFeeLog;
import cn.italkcloud.cph.mapper.VosFeeLogMapper;
import cn.italkcloud.cph.service.IVosFeeLogService;
import cn.italkcloud.cph.utils.SqlUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * VOS费用记录 服务实现类
 * </p>
 *
 * @author dominate
 * @since 2024-07-05
 */
@Service
public class VosFeeLogServiceImpl extends ServiceImpl<VosFeeLogMapper, VosFeeLog> implements IVosFeeLogService {

    @Override
    public List<VosFeeLog> query(FeeLogTypeEnum feeLogType, int accountId, int vosCustomerId, int size, int index) {
        QueryWrapper<VosFeeLog> query = new QueryWrapper<>();
        query.lambda()
                .eq(FeeLogTypeEnum.ALL.getCode() != feeLogType.getCode(), VosFeeLog::getType, feeLogType.getCode())
                .eq(0 != accountId, VosFeeLog::getAccountId, accountId)
                .eq(0 != vosCustomerId, VosFeeLog::getVosCustomerId, vosCustomerId)
                .orderByDesc(VosFeeLog::getId)
                .last(SqlUtil.indexLimit(size, index));
        return list(query);
    }

    @Override
    public List<VosFeeLog> loadRechargeLog(List<Integer> vosCustomerIdList, Date startDate, Date endDate) {
        QueryWrapper<VosFeeLog> query = new QueryWrapper<>();
        query.lambda()
                .eq(VosFeeLog::getType, FeeLogTypeEnum.RECHARGE.getCode())
                .between(VosFeeLog::getCreateTime, startDate, endDate)
                .in(VosFeeLog::getVosCustomerId, vosCustomerIdList);
        return list(query);
    }
}
